#include <malloc.h>

typedef struct {
	unsigned end_cont;
	unsigned end_non_cont;
} buf_t;

int longestSubarray(int num_a[], int num_nums) {
	unsigned first = (num_a[0] == 1);
	buf_t max_end = {
		.end_cont = first,
		.end_non_cont = 1,
	};
	unsigned max_len = 1;
	for (unsigned end_th = 1; end_th < num_nums; end_th++) {
		int value = num_a[end_th];
		unsigned len;
		if (value == 1) {
			max_end.end_cont = max_end.end_cont + 1;
			len = max_end.end_non_cont + 1;
		} else {
			len = max_end.end_cont + 1;
			max_end.end_cont = 0;
		}
		max_end.end_non_cont = len;
		if (len > max_len) {
			max_len = len;
		}
	}
	return max_len - 1;
}